//
//  ArticleManagementCell.m
//  reSearchDemo
//
//  Created by 科技 on 15/8/3.
//  Copyright (c) 2015年 Kiwaro. All rights reserved.
//

#import "ArticleManagementCell.h"

@interface ArticleManagementCell() {
    UILabel *context;
    UILabel *text;
    UIImageView *contextImage;
}
@end

@implementation ArticleManagementCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        context = [[UILabel alloc] init];
        context.font = [UIFont systemFontOfSize:20];
        context.textColor = [UIColor blackColor];
        context.numberOfLines = 0;
        
        text = [[UILabel alloc] init];
        text.font = [UIFont systemFontOfSize:14];
        text.textColor = [UIColor lightGrayColor];
        
        contextImage = [[UIImageView alloc] init];
        
        [self.contentView addSubview:context];
        [self.contentView addSubview:text];
        [self.contentView addSubview:contextImage];
    }
    
    return self;
}

-(void)setDic:(NSDictionary *)dic {
    CGSize textSize = [dic[@"context"] boundingRectWithSize:CGSizeMake(320, 588) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: context.font} context:nil].size;
    context.frame = CGRectMake(20, 10, textSize.width, textSize.height);
    context.text = dic[@"context"];
    contextImage.frame = CGRectMake(CGRectGetMaxX(context.frame) + 5, CGRectGetMaxY(context.frame) - 20, 20, 20);
    if (textSize.height < 25.0) {
        contextImage.image = [UIImage imageNamed:dic[@"contextImage"]];
    }
    
    
    text.frame = CGRectMake(CGRectGetMinX(context.frame), CGRectGetMaxY(context.frame), CGRectGetWidth(self.frame) - CGRectGetMinX(self.frame), 20);
    text.text = dic[@"text"];
    
    _height = CGRectGetMaxY(text.frame) + 10;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
